package com.opcode.nebulamobil.base.components;

import com.opcode.nebulamobil.base.interfaces.OnListViewBaseItemClickListener;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class ListViewBase extends ListView implements OnItemClickListener{

	private OnListViewBaseItemClickListener onListViewBaseItemClickListener;
	public static volatile long lastPressedTime=0;
	
	public ListViewBase(Context context) {
		super(context);
		this.setOnItemClickListener(this);
	}

	public ListViewBase(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.setOnItemClickListener(this);
	}	

	public ListViewBase(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		this.setOnItemClickListener(this);
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,long id) {
		long time=System.currentTimeMillis();
		if((time-lastPressedTime)>1500){
			lastPressedTime=time;		
			if(getOnListViewBaseItemClickListener()!=null){
				getOnListViewBaseItemClickListener().onListViewItemClick(parent, view, position, id);
			}
		}
	}

	public OnListViewBaseItemClickListener getOnListViewBaseItemClickListener() {
		return onListViewBaseItemClickListener;
	}

	public void setOnListViewBaseItemClickListener(
			OnListViewBaseItemClickListener onListViewBaseItemClickListener) {
		this.onListViewBaseItemClickListener = onListViewBaseItemClickListener;
	}
}
